#include"String.h"

void Test1(){
    String s1("mystring");
    String s2;
    cout << s1.size() << endl;
    cout << s2.size() << endl;
    
}

void Test2(){
    String s1("mystring");
    String s2(s1);
    cout << s1.c_str() << endl;
    cout << s2.c_str() << endl;
    
}

void Test3(){
    String s1("mystring");
    String s2("hello");
	s1 = s2;
    cout << s1.c_str() << endl;
    cout << s2.c_str() << endl;
    
}


//调用重载的输入输出流
void Test4(){
    String s1("mystring");
	cout << s1 << endl;
    String s2("das");
    //cin >> s2;
	s2.getline();
    cout << s2 << endl;

}

//迭代器访问
void Test5(){
	String s1("mystring");
    String::iterator it1 = s1.begin();
	while(it1 != s1.end()){
		cout << *it1;
		it1++;
	}
	cout << endl;
	//范围for是有迭代器支持的，这段代码最终会被编译器替换成迭代器
	for(auto& e : s1){
		cout << e;
	}
	cout << endl;
}

//增
void Test6(){
	String s1("hello");
	s1.push_back('w');
	//cout << s1.size() << endl;
	s1.push_back('o');
	//cout << s1.size() << endl;
	s1.push_back('r');
	//cout << s1.size() << endl;
	s1.push_back('l');
	cout << s1.size() << endl;
	cout << s1 << endl;
	s1.append("d xxxx");
	cout << s1.size() << endl;
	cout << s1 << endl;

	s1 += 'a';
	cout << s1 << endl;
	s1 += "bdc";
	cout << s1 << endl;
}



//插入
void Test7(){
	String s1("hello");
	cout << s1.size() << endl;
	cout << s1.insert(1, 'c') << endl;
	cout << s1.size() << endl; 
	cout << s1.insert(1, "world") << endl; 
	cout << s1.size() << endl;
}

//reserve和resize
void Test8(){
	String s1("hello");
	s1.reserve(10);
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;

	s1.resize(2);
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;

	s1.resize(20,'a');
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
}

//删查
void Test9(){
	String s1("hello world");	
	cout << s1.erase(1, 5) << endl;
	cout << s1.size() << endl;
	cout << s1.erase(1, 10) << endl;
	cout << s1.size() << endl;

	String s2("abcdefghj");	
	cout << s2.find('c') << endl;
	cout << s2.find('q') << endl;
	cout << s2.find("cde") << endl;
	cout << s2.find("aaa") << endl;
}
int main()
{
    Test1();
    Test2();
    Test3();
    //Test4();
    //Test5();
    //Test6();
    //Test7();
    //Test8();
    //Test9();
    return 0;
}